package com.hualan.controller;

import com.github.pagehelper.PageInfo;
import com.hualan.pojo.ConsultantLevel;
import com.hualan.pojo.Result;
import com.hualan.service.ConsultantLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hdx")
public class ConsultantLevelController {
    @Autowired
    private ConsultantLevelService consultantLevelService;
    @GetMapping("/selectLevel")
    public Result selectLevel (@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize, String levelName){
        PageInfo<ConsultantLevel> consultantLevelPageInfo = consultantLevelService.selectLevel(pageNum, pageSize, levelName);
        return Result.success(consultantLevelPageInfo);
    }
    @DeleteMapping("/deleteLevel/{id}")
    public Result deleteLevel(@PathVariable Long id){
        int i = consultantLevelService.deleteLevel(id);
        if (i!=0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }
    @DeleteMapping("/deleteLevels")
    public Result deleteLevels(@RequestBody List<Integer> ids){
        int i = consultantLevelService.deleteBatch(ids);
        if (i!=0){
            return Result.success("批量删除成功");
        }
        return Result.error("批量删除失败");
    }
    @PostMapping("/insertLevel")
    public Result insertLevel(@RequestBody ConsultantLevel record){
        int i = consultantLevelService.insertLevel(record);
        if (i!=0){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }
    @GetMapping("/updateLevel")
    public Result updateLevel(Integer id,String levelName){
        int i = consultantLevelService.updateLevel(id, levelName);
        if (i!=0){
            return Result.success("更新成功");
        }
        return Result.error("更新失败");
    }
    @PostMapping("/findLevel")
    public Result findLevel(){
        List<ConsultantLevel> consultantLevels = consultantLevelService.find();
        return Result.success(consultantLevels);
    }
}
